#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2018/12/4 19:00
# @Author  : yangdy
# @Email   : yangdy@egu360.com
# @File    : 高级-ProductofArrayExceptSelf.py
# @Software: PyCharm

from utils.main import main, opt_list


class Solution:
    def productExceptSelf(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        l = len(nums)
        a = []
        b = []
        u = 1
        for i in range(l):
            a.append(u)
            u *= nums[i]
        u = 1
        for i in range(l-1, -1, -1):
            b.append(u)
            u *= nums[i]
        b.reverse()
        ans = []
        for i in range(l):
            ans.append(a[i] * b[i])
        return ans


def opt(nums):
    solve = Solution()
    print(nums)
    print('ans:', solve.productExceptSelf(nums))


def opt1():
    nums = [1, 2, 3, 4]
    opt(nums)


if __name__ == '__main__':
    opt_list.append(opt1)
    main()

